package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.dp
 * @Author :  cheungming
 * @CreateTime : 2024-06-16 11:21:29
 * @Description : 完全平方数
 * @Version : 1.0
 */
public class Code279Test {

    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i * i; j <= n; j++) {
                dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
            }
        }

        return dp[n];
    }

    @Test
    public void test1() {
        assert numSquares(12) == 3;
    }

    @Test
    public void test2() {
        assert numSquares(13) == 2;
    }

    @Test
    public void test3() {
        assert numSquares(1) == 1;
    }
}
